#define  _CRT_SECURE_NO_WARNINGS
#define  _CRT_SECURE_NO_WARNINGS


#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 4
//顺序栈
typedef struct table
{
	int* base;      //栈底指针  数组名maybe
	int* top;       //栈顶指针
	int max;	//最大存
}table;

table* chushihua(table *s)
{
	s->base = (table*)malloc(MAXSIZE * sizeof(table));
	s->top = s->base;           // 栈顶指针等于栈底指针。
	s->max = MAXSIZE;
	return s;
}

void panduankongbiao(table *s)
{
	if (s->top == s->base)
	{
		printf("是\n");
	}
	else
		printf("不是\n");
}

void changdu(table *s)
{
	printf("%d\n", s->top - s->base);
}

table* qingkong(table* s)
{
	if (s->base != 0) // 不存在就是空的
		s->top = s->base;
	return s;
}

table* xiaohui(table *s)
{
	s->top = s->base = NULL;
	s->max = 0;      //所有都要清空 不能忘记max
	return s;
}

table* ruzhan(table *s)
{
	int n = 0;
	if (s->top - s->base != s->max)
	{
		scanf("%d", &n);        // 入栈需考虑是否满了
		*s->top = n;
		s->top++;
	}
	else
		printf("error\n");
	return s;
}

table* chuzhan(table *s)
{
	int n = 0;
	if (s->base != s->top)
	{
		s->top--;
		n = *s->top;            //出栈需考虑是否为空
		printf("%d\n", n);
	}
	else
		printf("error\n");
	return s;

}

void quzhanding(table *s)
{
	if (s->base != s->max)
		printf("%d\n", *(s->top - 1));       // 判断是否为空
	else
		printf("error\n");
}
int main()
{
  table	*s=(table*)malloc(MAXSIZE * sizeof(table)); 
  s=chushihua(s);        //数组传参.
	panduankongbiao(s);
	changdu(s);
	//s=qingkong(s);
	//s=xiaohui(s);
	s=ruzhan(s);
	s=chuzhan(s);
	quzhanding(s);
}

//链栈
#include<stdio.h>
#include<stdlib.h>
#define elem int
typedef struct table
{
	elem data;
	struct table* next;
}table;

table* chushihua(table* L)
{
	L->next = NULL;
	return L;
}

void panduankongbiao(table* L)
{
	if (L->next == NULL)
		printf("ture\n");
	else
		printf("false\n");
}

table* ruzhan(table* L)
{
	table* p = (table*)malloc(sizeof(table));
	int i = 0;
	scanf("%d", &i);
	p->data = i;
	p->next = L;
	L= p;
	printf("%d\n", p->data);
	return L;
}

table* chuzhan(table* L)
{
	int i = 0;
	i = L->data;
	table* p = L; 
	L = L->next;  // L始终指向an
	free(p);
	return L;
	
}

void quzhanding(table* L)
{
	if (L->next != NULL)
		printf("%d", L->data);
	else
		printf("error");

}
int main()
{
	table* L=(table*)malloc(sizeof(table));
	L=chushihua(L);
	panduankongbiao(L);
	L=ruzhan(L);
	L=chuzhan(L);
	quzhanding(L);
}